package com.project.webpage.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.project.webpage.dto.*;
import com.project.webpage.mapper.CzjczXlStateMapper;
import com.project.webpage.service.CzjczXlStateService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class CzjczXlStateServiceImpl implements CzjczXlStateService {

    @Resource
    private CzjczXlStateMapper czjczXlStateMapper;

    @Override
    @DS("master")
    public List<ShCzllDto> getListForPage(BaseParam param) {
        return czjczXlStateMapper.selectListByUid(param);
    }

    @Override
    @DS("master")
    public List<ShCzllDto> getCzxlListForPage(SearchByRqParam param) {
        return czjczXlStateMapper.selectCzxlListByUid(param);
    }

    @Override
    @DS("master")
    public SsStateDto getSsTotal(BaseParam param) {
        SsStateDto dto = new SsStateDto();
        dto.setZaixian(czjczXlStateMapper.selectSsStateByUid(param));
        dto.setLixian(czjczXlStateMapper.selectSslixianByUid(param));
        dto.setLixian1(czjczXlStateMapper.selectSslixian1ByUid(param));
        dto.setLixian2(czjczXlStateMapper.selectSslixian2ByUid(param));
        dto.setLixian3(czjczXlStateMapper.selectSslixian3ByUid(param));
        dto.setYouxiao(czjczXlStateMapper.selectSsCorrectByUid(param));
        dto.setNopp(dto.getZaixian() - dto.getYouxiao());
        dto.setWuxiao(dto.getLixian() + dto.getNopp());
        return dto;
    }

    @Override
    @DS("master")
    public List<CzxlDto> getCzxlForPage(XlzdParam param) {
        return czjczXlStateMapper.selectCzxlByUid(param);
    }

    @Override
    @DS("master")
    public List<ClwDto> getClwForPage(ClwParam param) {
        List<ClwDto> list = new ArrayList<>();
//        param.setTableName("TB_CLWZ" + param.getRq().replace("-", ""));
//        List<ClwDto> tableList = czjczXlStateMapper.selectClwTable(param);
//        if (tableList.size() > 0) {
//            param.setTableName("GJ_BUS_CZJCZ.dbo.TB_CLWZ" + param.getRq().replace("-", ""));
//            list = czjczXlStateMapper.selectClwByUid(param);
//        }
        try {
            param.setTableName("GJ_BUS_CZJCZ.dbo.TB_CLWZ" + param.getRq().replace("-", ""));
            list = czjczXlStateMapper.selectClwByUid(param);
        } catch (Exception e) {
            return list;
        }
        return list;
    }
}
